﻿<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.XML" %>

<script language="VB" runat="server">

    Dim TTT As String = "home"
    Public Sql As String = String.Concat("SELECT * FROM ALL_RSS WHERE ABS=True OR ADL=True") _
         , cmd As OleDbCommand = New OleDbCommand(Sql, global_asax.conn1) _
         , da As OleDbDataAdapter = New OleDbDataAdapter() _
         , ds As DataSet = New DataSet() _
         , Table As DataTable _
         , IRow As DataRow
    
    Function CheckBid() As Integer
        ' 
        Dim bid As String _
                = Request.Url.ToString _
          , value As Integer = -1
        '
        '------------
        '|  TAG`S   |
        '------------
            If bid.Split("?").Length > 1 Then
                '
                Try
                    Dim ID As Integer _
                        = Integer.Parse(bid.Split("=")(1))
                    Dim cmd2 As New OleDbCommand()
                    cmd2.Connection = global_asax.conn1
                    Dim query As String = String.Concat("DELETE * FROM ALL_RSS WHERE ID=", Integer.Parse(ID), "")
                    cmd2.CommandText = query
                    cmd2.ExecuteNonQuery()
                Catch ex As Exception
                    'Windows.Forms.MessageBox.Show(ex.Message)
                End Try
                Response.Redirect("ADMIN.ASPX")
            End If
        '
        Return value
        ''
    End Function
    
    Public Sub Inicialize()
        With da
            .SelectCommand = cmd
            .Fill(ds, "ALL_RSS")
        End With
        Table = ds.Tables(0)
        '------------------
        Dim foundRows() As DataRow _
             = Table.Select(Nothing, "RATE DESC")
        Dim ITemp As DataTable = Table.Copy()
        ITemp.Rows.Clear()
        For Each r As DataRow In foundRows
            ITemp.ImportRow(r)
        Next
        Table = ITemp
        '------------------
    End Sub
    
    Public CAT As Dictionary(Of String, String) _
            = New Dictionary(Of String, String)
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '
        Dim PID As Integer = CheckBid()
        Try
            '
            Inicialize()
            '----------------{
            If NOT TB_METADATA.Text.Length >1
                TB_METADATA.Text = File.ReadAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/METADATA.TXT")))
            End If
            If NOT TB_HEADER.Text.Length >1
                TB_HEADER.Text = File.ReadAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/HEADER.TXT")))
            End If
            If NOT TB_FOOTER.Text.Length >1
                TB_FOOTER.Text = File.ReadAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/FOOTER.TXT")))
            End If
            If NOT TB_MENU.Text.Length >1
                TB_MENU.Text = File.ReadAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/MENU.TXT")))
            End If
            If NOT TB_TAGS.Text.Length >1
                TB_TAGS.Text = File.ReadAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/TAGS.TXT")))
            End If
            If NOT TB_ADS_AND_STATS.Text.Length >1
                TB_ADS_AND_STATS.Text = File.ReadAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/ADS_AND_STATS.TXT")))
            End If

            '}-------
            '
        Catch ex As Exception
        End Try
        '
    End Sub
    
    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        '
        Dim T1 As String = Login1.UserName _ 
          , T2 As String = Login1.Password _ 
          , L1 as String = Nothing _ 
          , L2 As String = Nothing 
       Dim [_PAGE_PATH] As String _
                    = String.Concat(Server.MapPath("App_Data/adm.xml"))
        Using vr As New XmlValidatingReader(New XmlTextReader([_PAGE_PATH]))
            vr.ValidationType = ValidationType.Schema
            Try
                vr.MoveToContent() 
                While vr.Read
                    Select vr.NodeType 
                        Case XmlNodeType.Element
                            Select vr.Name
                                Case "UserName"
                                    L1 = vr.ReadElementString()
                                Case "Password"
                                    L2 = vr.ReadElementString()
                            End Select
                    End Select
                End While
            Catch ex As Exception
                Login1.FailureText  = ex.Message
            End Try
        End Using
        '
        If (T1=L1) AND (T2=L2) Then
            HttpContext.Current.Session.Add("LOGIN", True)
            Response.Redirect("ADMIN.ASPX")
            'Login1.FailureTextStyle.ForeColor = Drawing.Color.Green 
            'Login1.FailureText  = "Ok." 
        Else
            Login1.FailureTextStyle.ForeColor = Drawing.Color.Red 
            Login1.FailureText  = "[!]Error login!" 
        End If
        '
    End Sub
    
    Protected Sub IF_METADATA_SAVE(ByVal sender As Object, ByVal e As System.EventArgs)
        '----------------{
        Try
            File.WriteAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/METADATA.TXT")), TB_METADATA.Text)
        Catch ex As Exception
        End Try
        '}-------
    End Sub
 
    Protected Sub IF_HEADER_SAVE(ByVal sender As Object, ByVal e As System.EventArgs)
        '----------------{
        Try
            File.WriteAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/HEADER.TXT")), TB_HEADER.Text)
        Catch ex As Exception
        End Try
        '}-------
    End Sub
 
    Protected Sub IF_FOOTER_SAVE(ByVal sender As Object, ByVal e As System.EventArgs)
        '----------------{
        Try
            File.WriteAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/FOOTER.TXT")), TB_FOOTER.Text)
        Catch ex As Exception
        End Try
        '}-------
    End Sub

    Protected Sub IF_MENU_SAVE(ByVal sender As Object, ByVal e As System.EventArgs)
        '----------------{
        Try
            File.WriteAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/MENU.TXT")), TB_MENU.Text)
        Catch ex As Exception
        End Try
        '}-------
    End Sub

    Protected Sub IF_TAGS_SAVE(ByVal sender As Object, ByVal e As System.EventArgs)
        '----------------{
        Try
            File.WriteAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/TAGS.TXT")), TB_TAGS.Text)
        Catch ex As Exception
        End Try
        '}-------
    End Sub
    
    Protected Sub IF_ADS_AND_STATS_SAVE(ByVal sender As Object, ByVal e As System.EventArgs)
        '----------------{
        Try
            File.WriteAllText(String.Concat(Server.MapPath("App_Data/TEMPLATES/ADS_AND_STATS.TXT")), TB_ADS_AND_STATS.Text)
        Catch ex As Exception
        End Try
        '}-------
    End Sub
    
</script>

<%@ Page Title="4EK.ORG DIRECTORY PROJECT" Language="VB" MasterPageFile="~/Site.Master" ValidateRequest="false" WarningLevel ="0" AutoEventWireup="false" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

              <asp:Panel ID="Panel1" runat="server" Height="580px" 
                  ScrollBars="Vertical" BorderStyle="Double" EnableTheming="True" 
                  HorizontalAlign="Left">

                  <%
                  If HttpContext.Current.Session("LOGIN") = True Then
                      %>                          
                          


                                                                <div id="TabbedPanels1" class="TabbedPanels">
                                                                  <ul class="TabbedPanelsTabGroup">
                                                                    <li class="TabbedPanelsTab" tabindex="0">Row`s</li>
                                                                    <li class="TabbedPanelsTab" tabindex="1">Template.METADATA</li>
                                                                    <li class="TabbedPanelsTab" tabindex="2">Template.HEADER</li>
                                                                    <li class="TabbedPanelsTab" tabindex="3">Template.FOOTER</li>
                                                                    <li class="TabbedPanelsTab" tabindex="4">Template.MENU</li>
                                                                    <li class="TabbedPanelsTab" tabindex="6">Template.TAGS</li>
                                                                    <li class="TabbedPanelsTab" tabindex="7">Template.ADS_AND_STATS</li>
                                                                  </ul>
                                                                  <div class="TabbedPanelsContentGroup">
                                                                    <div class="TabbedPanelsContent">


                                                                      &nbsp;&nbsp;ID &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| InDIR | SPA | AD | COMM <br />
                                                                      <%
                                                                          Dim [_PID] As Integer _ 
                                                                                = HttpContext.Current.Session("PID")
                                                                          If [_PID] > 0 Then
                                                                              '
                                                                              '
                                                                          Else
                                                                              '
                                                                              %>

                                                                                <% 
                                                                                        Dim CUR_PAGE_ID As Integer = 0 _
                                                                                                 , IIID As Integer = 0
                                                                                        For ID As Integer = 0 To Table.Rows.Count - 1
                                                                                            Dim Row As DataRow = Table.Rows(ID)
                                                                                            %>
                                                                                                <a href='Default.aspx?ID=<%=Row("id")%>' target="_blank" style="text-align: left">
                                                                                                    <input id="Button3" type="button" value="<%=Row("id")%>" style="width: 80px; height: 22px" />
                                                                                                </a>
                                                                                                &nbsp;&nbsp;<a title="<%=Row("TITLE")%>" href="<%=Row("link")%>" target="_blank">Indir</a>
                                                                                                &nbsp;&nbsp;
                                                                                                <%
                                                                                                If Row("ABS")= True Then
                                                                                                    %>
                                                                                                    <asp:CheckBox ID="CB1" runat="server" Enabled="False" Checked="True" />
                                                                                                    <%
                                                                                                Else
                                                                                                    %>
                                                                                                    <asp:CheckBox ID="CB2" runat="server" Enabled="False" Checked="False" />
                                                                                                    <%
                                                                                                End If
                                                                                                %>

                                                                                                <%
                                                                                                If Row("ADL")= True Then
                                                                                                    %>
                                                                                                    <asp:CheckBox ID="CB3" runat="server" Enabled="False" Checked="True" />
                                                                                                    <%
                                                                                                Else
                                                                                                    %>
                                                                                                    <asp:CheckBox ID="CB4" runat="server" Enabled="False" Checked="False" />
                                                                                                    <%
                                                                                                End If
                                                                                                %>
                                                                                                <a href='?del=<%=Row("id")%>'>
                                                                                                    <input id="Button" type="button" value="delete?" style="background-color: #FF6666" />
                                                                                                </a>
                                                                                                <br />
                                                                                            <%                
                                                                                        Next
                                                                          End If
                                                                      %>

                                                                    </div>

                                                                    <div class="TabbedPanelsContent">
                                                                       <asp:TextBox ID="TB_METADATA"
                                                                            BorderStyle="Solid" Width="100%" Height="480px" TextMode="MultiLine"
                                                                            Columns="2"
                                                                            MaxLength="3"
                                                                            Text="1"
                                                                            runat="server"/>
                                                                       <br />
                                                                       <asp:Button ID="BTN_METADATA_SAVE"
                                                                            Text="Save"
                                                                            OnClick="IF_METADATA_SAVE"
                                                                            runat="server"/>
                                                                    </div>

                                                                    <div class="TabbedPanelsContent">
                                                                       <asp:TextBox ID="TB_HEADER"
                                                                            BorderStyle="Solid" Width="100%" Height="480px" TextMode="MultiLine"
                                                                            Columns="2"
                                                                            MaxLength="3"
                                                                            Text="1"
                                                                            runat="server"/>
                                                                       <br />
                                                                       <asp:Button ID="BTN_HEADER_SAVE"
                                                                            Text="Save"
                                                                            OnClick="IF_HEADER_SAVE"
                                                                            runat="server"/>
                                                                    </div>

                                                                    <div class="TabbedPanelsContent">
                                                                       <asp:TextBox ID="TB_FOOTER"
                                                                            BorderStyle="Solid" Width="100%" Height="480px" TextMode="MultiLine"
                                                                            Columns="2"
                                                                            MaxLength="3"
                                                                            Text="1"
                                                                            runat="server"/>
                                                                       <br />
                                                                       <asp:Button ID="BTN_FOOTER_SAVE"
                                                                            Text="Save"
                                                                            OnClick="IF_FOOTER_SAVE"
                                                                            runat="server"/>
                                                                    </div>

                                                                    <div class="TabbedPanelsContent">
                                                                       <asp:TextBox ID="TB_MENU"
                                                                            BorderStyle="Solid" Width="100%" Height="480px" TextMode="MultiLine"
                                                                            Columns="2"
                                                                            MaxLength="3"
                                                                            Text="1"
                                                                            runat="server"/>
                                                                       <br />
                                                                       <asp:Button ID="BTN_MENU_SAVE"
                                                                            Text="Save"
                                                                            OnClick="IF_MENU_SAVE"
                                                                            runat="server"/>
                                                                    </div>

                                                                    <div class="TabbedPanelsContent">
                                                                       <asp:TextBox ID="TB_TAGS"
                                                                            BorderStyle="Solid" Width="100%" Height="480px" TextMode="MultiLine"
                                                                            Columns="2"
                                                                            MaxLength="3"
                                                                            Text="1"
                                                                            runat="server"/>
                                                                       <br />
                                                                       <asp:Button ID="BTN_TAGS_SAVE"
                                                                            Text="Save"
                                                                            OnClick="IF_TAGS_SAVE"
                                                                            runat="server"/>
                                                                    </div>

                                                                    <div class="TabbedPanelsContent">
                                                                       <asp:TextBox ID="TB_ADS_AND_STATS"
                                                                            BorderStyle="Solid" Width="100%" Height="480px" TextMode="MultiLine"
                                                                            Columns="2"
                                                                            MaxLength="3"
                                                                            Text="1"
                                                                            runat="server"/>
                                                                       <br />
                                                                       <asp:Button ID="BTN_ADS_AND_STATS_SAVE"
                                                                            Text="Save"
                                                                            OnClick="IF_ADS_AND_STATS_SAVE"
                                                                            runat="server"/>
                                                                    </div>

                                                                  </div>
                                                                </div>
                                                                <script type="text/javascript">
                                                                    var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
                                                                </script>                                            

                      <%      
                  Else
                      %>                          
                        <p>
                            <br />
                            <asp:Login ID="Login1" runat="server">
                            </asp:Login>
                        </p>
                      <%      
                  End If
                  %>

              </asp:Panel>  

</asp:Content>